package com.c6906.vdam.das.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.c6906.vdam.das.dao.EWVehiclesWarnDAO;
import com.c6906.vdam.das.model.dto.PreWarnDTO;
import com.c6906.vdam.das.model.entity.EWVehiclesWarn;
import com.c6906.vdam.das.service.EWVehiclesWarnService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


@Service
public class EWVehiclesWarnServiceImpl extends ServiceImpl<EWVehiclesWarnDAO, EWVehiclesWarn> implements EWVehiclesWarnService {
    @Resource
    EWVehiclesWarnDAO ewVehiclesWarnDAO;

    @Override
    public Long countWarns(String ewTypeId, String vehiclesCode, String date) {
        LambdaQueryWrapper<EWVehiclesWarn> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EWVehiclesWarn::getEwTypeId, ewTypeId);
        queryWrapper.eq(EWVehiclesWarn::getVehiclesCode, vehiclesCode);
        Date startTime = DateUtil.beginOfMonth(DateUtil.parseDate(date));
        Date endTime = DateUtil.endOfMonth(DateUtil.parseDate(date));
        queryWrapper.between(EWVehiclesWarn::getCreateTime, startTime, endTime);
        return ewVehiclesWarnDAO.selectCount(queryWrapper);
    }

    @Override
    public List<PreWarnDTO> getWarnVehMonth(String ewTypeId, Date start, Date end, int limit) {
        return ewVehiclesWarnDAO.getWarnVehMonth(ewTypeId, start, end, limit);
    }
}
